package com.elminster.dao.impl;

import java.sql.Date;
import java.util.List;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;

import com.elminster.dao.IDetailDao;
import com.elminster.dao.common.impl.GenericDaoImpl;
import com.elminster.entity.base.Detail;

/**
 * A data access object (DAO) providing persistence and search support for
 * Detail entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.elminster.entity.base.Detail
 * @author MyEclipse Persistence Tools
 */
@Component
public class DetailDaoImpl extends GenericDaoImpl<Detail, Integer> implements IDetailDao {
    private static final Log log = LogFactory.getLog(DetailDaoImpl.class);
    // property constants
    public static final String CATALOG_ID = "catalogId";
    public static final String OWNER_ID = "ownerId";
    public static final String AMOUNT = "amount";
    
    public DetailDaoImpl() {
        this(Detail.class);
    }

    public DetailDaoImpl(Class<Detail> type) {
        super(type);
    }
    
    protected void initDao() {
        // do nothing
    }

    public List<Detail> findByCatalogId(Object catalogId) {
        return findByProperty(CATALOG_ID, catalogId);
    }
    
    public List<Detail> findByOwnId(Object ownerId) {
        return findByProperty(OWNER_ID, ownerId);
    }

    public List<Detail> findByAmount(Object amount) {
        return findByProperty(AMOUNT, amount);
    }

    public List<Detail> findByDatePeriod(Date start, Date end) {
        log.debug("find by date period: [" + start.toString() + ","  + end.toString() + "]");
        String hql = "from Detail d where d.occurTime >= ? and d.occurTime <= ?";
        Object[] params = new Object[] {start, end};
        return findByHql(hql, params);
    }
}